package per.chenxin.util.tcp.http;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketTimeoutException;

public class TunnelProxyServer {
	static String CONFIG = "config.ini";

	public static void main(String[] args) throws FileNotFoundException,
			IOException {
		ProxyEntity proxyEntity = ProxyEntity
				.readFromIni(args.length < 1 ? CONFIG : args[0]);

		ServerSocket serverSocket;
		try {
			serverSocket = new ServerSocket(proxyEntity.getLocalPort());
			serverSocket.setSoTimeout(1000);
			while (true) {
				try {
					Socket socketClient = serverSocket.accept();
					(new Thread(new SocketThread(socketClient, proxyEntity)))
							.start();
				} catch (SocketTimeoutException sockettimeoutexception) {
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

}
